import 'package:flash/flash.dart';
import 'package:flutter/material.dart';
import 'package:flutter_scan_tool/models/app_theme.dart';

enum MessageType { alert, message, success, error }

class FlashHelper {
  static Future<T?> toast<T>(
      BuildContext context, String message, MessageType messageType) async {
    return showFlash<T>(
        context: context,
        duration: const Duration(milliseconds: 4000),
        builder: (context, controller) {
          return Flash.bar(
            margin: const EdgeInsets.only(left: 24, right: 24),
            position: FlashPosition.top,
            brightness:
                AppTheme.appTheme.isDark() ? Brightness.light : Brightness.dark,
            backgroundColor: Colors.transparent,
            controller: controller,
            child: Container(
              alignment: Alignment.center,
              padding: const EdgeInsets.all(16),
              height: 80,
              decoration: BoxDecoration(
                  color: messageType == MessageType.alert
                      ? const Color.fromARGB(255, 242, 79, 136)
                      : const Color.fromARGB(255, 101, 89, 184),
                  shape: BoxShape.rectangle,
                  borderRadius: const BorderRadius.all(Radius.circular(16)),
                  boxShadow: AppTheme.appTheme.coloredBoxShadow()),
              child: Text(
                message,
                style: AppTheme.appTheme.headline1(
                    textColor: Colors.white,
                    fontWeight: FontWeight.normal,
                    fontSize: 16),
              ),
            ),
          );
        });
  }
}
